package view.controller;

import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.image.ImageView;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
import view.AlertWindow;
import view.Disk;
import view.GUI;
import view.NewPropertyWindow;


import java.awt.*;
import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;


public class AlertWindowController implements Initializable {
    public AlertWindowController() {

    }

    private Stage stage;

    @FXML
    private ImageView disk;

    @FXML
    private ImageView property;

    @FXML
    private Button bu;

    @FXML
    private AnchorPane an;

    //打开磁盘面板
    public void opendisk() {
        BorderPane settings = null;
        try {
            settings = FXMLLoader.load(getClass().getClassLoader().getResource("Disk.fxml"));
        } catch (IOException e) {
            e.printStackTrace();
        }
        GUI.Diskdisplay(settings);
    }

    //打开设置面板
    public void openproperty() throws IOException {
        ControllerTool controllerTool = new ControllerTool("NewPropertyWindow.fxml");
        Parent parent = controllerTool.getParent();
        NewPropertyWindow.display(parent);
    }

    public void close() {
        //System.out.println("close");
        Stage stage = (Stage) bu.getScene().getWindow();
        stage.close();
    }

    private double xOffset;
    private double yOffset;

    @Override
    public void initialize(URL url, ResourceBundle resourceBundle) {
        //System.out.println("windows initialize");
        an.setOnMouseDragged(event -> {
            event.consume();
            Stage stage = getStage();
            stage.setX(event.getScreenX() - xOffset);
            stage.setY(event.getScreenY() - yOffset);
        });
        an.setOnMousePressed(event -> {
            event.consume();
            xOffset = event.getSceneX();
            yOffset = event.getSceneY();
        });

        property.setStyle("-fx-background-radius: 10px");
        property.setStyle("-fx-border-radius: 10px");
    }

    private Stage getStage() {
        if (stage == null) {
            stage = (Stage) an.getScene().getWindow();
        }
        return stage;
    }


}
